home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Found / FWExcLib / Include / FWExcDef.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-21  |  6.7 KB  |  273 lines  |  [TEXT/MPS ]

  1. #ifndef FWEXCDEF_H
  2. #define FWEXCDEF_H
  3. //========================================================================================
  4. //
  5. //    File:                FWExcDef.h
  6. //    Release Version:    $ 1.0d1 $
  7. //
  8. //    Creation Date:        3/28/94
  9. //
  10. //    Copyright:    © 1994 by Apple Computer, Inc., all rights reserved.
  11. //
  12. //========================================================================================
  13.  
  14. #ifndef   FWONSTAC_H
  15. #include "FWOnStac.h"
  16. #endif
  17.  
  18. #if defined(FW_DEBUG) && !defined(FWTRACE_H)
  19. #include "FWTrace.h"
  20. #endif
  21.  
  22. #ifndef   FWAUTODE_H
  23. #include "FWAutoDe.h"
  24. #endif
  25.  
  26. #ifndef   FWCLAINF_H
  27. #include "FWClaInf.h"
  28. #endif
  29.  
  30. #ifndef   FWEXCEPT_H
  31. #include "FWExcept.h"
  32. #endif
  33.  
  34. #ifndef   FWTRYBLO_H
  35. #include "FWTryBlo.h"
  36. #endif
  37.  
  38. #ifndef   FWEXCRUN_H
  39. #include "FWExcRun.h"
  40. #endif
  41.  
  42. #ifndef   FWDELSTA_H
  43. #include "FWDelSta.h"
  44. #endif
  45.  
  46. #if !defined(FWEXCLOG_H) && defined(FW_DEBUG)
  47. #include "FWExcLog.h"
  48. #endif
  49.  
  50. #if !defined(FWNEWHEL_H) && defined(FW_USE_NEW_HELPER)
  51. #include "FWNewHel.h"
  52. #endif
  53.  
  54. #ifdef FW_BAD_CODE_GENERATION
  55. int ReturnFalse();
  56. int ReturnTrue();
  57. #define FW_BEL_FALSE ::ReturnFalse()
  58. #define FW_BEL_TRUE ::ReturnTrue()
  59. #else
  60. #define FW_BEL_FALSE 0
  61. #define FW_BEL_TRUE 1
  62. #endif
  63.  
  64. //========================================================================================
  65. // Exception Handling Interface Macros
  66. //========================================================================================
  67.  
  68. #define FW_VOLATILE(a) ((void) &a)
  69. #define FW_DUMMY_RETURN_TRUE return 1;
  70.  
  71. #ifndef FW_DISABLE_BEL
  72.  
  73. #ifdef FW_USE_NEW_HELPER    
  74. #define FW_NEW(class, args) (class*)                                            \
  75.         (                                                                        \
  76.         new(_FW_CPrivNewHelper(::operator new, ::operator delete)) class##args,     \
  77.         (void*) _FW_CPrivNewHelper::PopNewHelper()->ForgetObject()                \
  78.         )
  79. #else
  80. #define FW_NEW(class, args) new class##args
  81. #endif
  82.  
  83. #ifdef FW_DEBUG
  84. // These two defines are solely to make the code immediately below more readable
  85. #define FW_SAVE_TRACE_STATE \
  86.     FW_SPrivTraceGlobals& __traceGlobals = FW_CPrivTraceTaskGlobals::GetTraceGlobals(); \
  87.     unsigned short __traceDepth = __traceGlobals.gTraceDepth;
  88. #define FW_RESTORE_TRACE_STATE \
  89.     __traceGlobals.gTraceDepth = __traceDepth;
  90. #else
  91. #define FW_SAVE_TRACE_STATE 
  92. #define FW_RESTORE_TRACE_STATE 
  93. #endif
  94.  
  95. #define FW_TRY \
  96.     { \
  97.         FW_SPrivExceptionGlobals& __excGlobals = FW_CExceptionTaskGlobals::GetExceptionGlobals(); \
  98.         FW_SAVE_TRACE_STATE \
  99.         jmp_buf    __jumpBuffer; \
  100.         if(setjmp(__jumpBuffer) == 0) \
  101.         { \
  102.             _FW_CTryBlockContext __context(__excGlobals, __jumpBuffer);
  103.  
  104. #define FW_CATCH_BEGIN \
  105.         } \
  106.         else \
  107.         { \
  108.             FW_RESTORE_TRACE_STATE \
  109.             if (FW_BEL_FALSE) \
  110.             {
  111.  
  112. #define FW_CATCH(class, error) \
  113.             } \
  114.             else if (__excGlobals.gThrownException->__IsKindOf(FW_CLASS_REFERENCE(class))) \
  115.             { \
  116.                 class error = * (class*) __excGlobals.gThrownException; \
  117.                 _FW_CExceptionRuntime::CaughtException(__excGlobals, &error);
  118.  
  119. #define FW_CATCH_REFERENCE(class, error) \
  120.             } \
  121.             else if (__excGlobals.gThrownException->__IsKindOf(FW_CLASS_REFERENCE(class))) \
  122.             { \
  123.                 class & error = *(class*) __excGlobals.gThrownException; \
  124.                 _FW_CExceptionRuntime::CaughtReferenceException(__excGlobals);
  125.  
  126. #define FW_CATCH_NO_INSTANCE(class) \
  127.             } \
  128.             else if (__excGlobals.gThrownException->__IsKindOf(FW_CLASS_REFERENCE(class))) \
  129.             { \
  130.                 _FW_CExceptionRuntime::CaughtNoInstanceException(__excGlobals);
  131.  
  132. #define FW_CATCH_EVERYTHING() \
  133.             } \
  134.             else if (FW_BEL_TRUE) \
  135.             { \
  136.                 _FW_CExceptionRuntime::CaughtEverythingException(__excGlobals);
  137.  
  138. #define FW_CATCH_END \
  139.             } \
  140.             else \
  141.             { \
  142.                 _FW_CExceptionRuntime::KeepThrowing(__excGlobals); \
  143.             } \
  144.         _FW_CExceptionRuntime::CatchCleanup(__excGlobals); \
  145.         } \
  146.     }
  147.  
  148. #define FW_THROW(error) \
  149.     _FW_CExceptionRuntime::Throw(error)
  150.  
  151. #define FW_THROW_SAME() \
  152.     _FW_CExceptionRuntime::ThrowSame()
  153.  
  154. #define FW_THROWS_NOTHING() \
  155.     _FW_SThrowGuard __nothing
  156.  
  157. #define FW_THROWS(class) \
  158.     _FW_SThrowGuard __nothing##class(FW_CLASS_REFERENCE(class))
  159.  
  160. #ifdef FW_USE_NEW_HELPER    
  161.     #define FW_END_CONSTRUCTOR    \
  162.         _FW_CExceptionRuntime::EndConstructor(this, sizeof(*this));
  163.     #define FW_START_DESTRUCTOR \
  164.         if (_FW_PrivIsOnStack(this)) \
  165.             _FW_CDeleteStack::PopIfTopEquals(this);
  166. #else
  167.     #define FW_END_CONSTRUCTOR \
  168.         if (_FW_PrivIsOnStack(this)) \
  169.             _FW_CDeleteStack::Push(this);
  170.     #define FW_START_DESTRUCTOR \
  171.         if (_FW_PrivIsOnStack(this)) \
  172.             _FW_CDeleteStack::PopIfTopEquals(this);
  173. #endif
  174.  
  175.  
  176.  
  177.  
  178. #else
  179.     // This is how to turn exceptions off
  180.     
  181.     #define FW_TRY \
  182.     { \
  183.         if(FW_BEL_TRUE) \
  184.         {
  185.  
  186.     #define FW_CATCH_BEGIN \
  187.         } \
  188.         else \
  189.         { \
  190.             if (FW_BEL_FALSE) \
  191.             {
  192.     
  193.     #define FW_CATCH(class, error) \
  194.             } \
  195.             else if (FW_BEL_FALSE) \
  196.             { \
  197.                 class error = * (class*) 0;
  198.  
  199.     #define FW_CATCH_REFERENCE(class, error) \
  200.             } \
  201.             else if (FW_BEL_FALSE) \
  202.             { \
  203.                 class & error = *(class*) 0;
  204.                     
  205.     #define FW_CATCH_NO_INSTANCE(class) \
  206.             } \
  207.             else if (FW_BEL_FALSE) \
  208.             {
  209.  
  210.     #define FW_CATCH_EVERYTHING() \
  211.             } \
  212.             else if (FW_BEL_TRUE) \
  213.             {
  214.  
  215.     #define FW_CATCH_END \
  216.             } \
  217.             else \
  218.             { \
  219.             } \
  220.         } \
  221.     }
  222.  
  223.     #define FW_THROW(error) FW_DEBUG_MESSAGE(#error)
  224.     #define FW_THROW_SAME()
  225.     #define FW_THROWS_NOTHING()
  226.     #define FW_THROWS(class)
  227.  
  228.     #define FW_END_CONSTRUCTOR
  229.     #define FW_START_DESTRUCTOR
  230.     #define FW_NEW(class, args) new class##args
  231. #endif
  232.  
  233. //========================================================================================
  234. // Exception Logging Macros
  235. //========================================================================================
  236.  
  237. #ifdef FW_DEBUG
  238. #define FW_LOG_OR_TRIGGER_EXCEPTION(class, instance) \
  239.     { \
  240.         FW_SPrivExceptionLog& __logGlobals = _FW_CExceptionLog::GetExceptionLogGlobals(); \
  241.         if (__logGlobals.gLogEnabled) \
  242.         { \
  243.             _FW_CExceptionLog::LogException(FW_CLASS_REFERENCE(class)); \
  244.         } \
  245.         else if ((__logGlobals.gTriggerClass == FW_CLASS_REFERENCE(class)) || __logGlobals.gTriggerPoint)\
  246.         { \
  247.             _FW_CExceptionLog::TriggerException(FW_CLASS_REFERENCE(class), instance); \
  248.         } \
  249.     }
  250. #define FW_CAUSE_EXCEPTION_BY_NAME(name) _FW_CExceptionLog::CauseException(FW_CLASS_REFERENCE(name));
  251. #define FW_CAUSE_EXCEPTION_BY_COUNT(count) _FW_CExceptionLog::CauseException(count);
  252. #else
  253. #define FW_LOG_OR_TRIGGER_EXCEPTION(class, instance)
  254. #define FW_CAUSE_EXCEPTION_BY_NAME(name)
  255. #define FW_CAUSE_EXCEPTION_BY_COUNT(count)
  256. #endif
  257.  
  258. //========================================================================================
  259. // Exception Debugging Macros
  260. //========================================================================================
  261.  
  262. #ifdef FW_DEBUG
  263. #define FW_FWEAK_ON_THROW(class) _FW_CExceptionRuntime::SetBreakOnThrow(FW_CLASS_REFERENCE(class))
  264. #define FW_NO_FWEAK_ON_THROW      _FW_CExceptionRuntime::SetBreakOnThrow(NULL)
  265. #define FW_EXCEPTION_FWEAK_CONTEXT(class) FW_CExceptionBreakContext __BreakContext(FW_CLASS_REFERENCE(class))
  266. #else
  267. #define FW_FWEAK_ON_THROW(class) 
  268. #define FW_NO_FWEAK_ON_THROW      
  269. #define FW_EXCEPTION_FWEAK_CONTEXT(class) 
  270. #endif
  271.  
  272. #endif
  273.